import java.util.ArrayList;
import java.util.Collections;

public class h_1 implements Runnable {
    h_1_box h;
    int i=0;
    public h_1(h_1_box h,int i) {
        this.h = h;
        this.i=i;
    }

    /*	ArrayList<Integer> list1=new ArrayList<>();
        ArrayList<Integer> list2=new ArrayList<>();*/
    @Override
    public void run() {
        Thread.currentThread().setName("抽奖箱"+i);
        ArrayList<Integer> bokList=new ArrayList<>();
        while(true){
            synchronized (h_1.class) {
                if(h.list.size()==0){
                    int sum=0;
                    if(bokList.size()!=0){
                        for (Integer i:bokList
                        ) {
                            if(i==h.max)
                                System.out.println("在此次抽奖过程中，"+Thread.currentThread().getName()+"产生了最大得金额，"+h.max+"元");
                            sum=sum+i;
                        }
                        System.out.println(Thread.currentThread().getName()+"中了，"+bokList+" 总额为"+sum);
                    }
                    break;
                }else{
                    //继续抽奖
                    Collections.shuffle(h.list);
                    Integer prize = h.list.remove(0);
                    System.out.println(Thread.currentThread().getName()+"又产生了一个:"+prize+"元大奖");
                    bokList.add(prize);
                }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
